//app.js106 156
var zhmd5 = require('utils/zhmd5.js')
var CryptoJS = require('utils/aes.js')
var funBase64 = require('utils/base64.js')
// const ald = require('utils/ald-stat.js')
const baseUrls = {
  develop: {
    // api_url: 'http://10.10.10.232:81/',
    // api_url2: 'http://10.10.25.110:8000/',
    // jp_api_url: 'http://10.10.10.232:666/',
    // jp_api_url_search: 'http://10.10.10.232:888/',
    // jp_api_web_url: 'http://10.10.10.232:8081/',
    api_url: 'https://apiwf.feijiu.net/',
    api_url2: 'https://feijiu-recycle.feijiu.com.cn/',
    jp_api_url: 'https://webservice.feijiu.net/',
    jp_api_url_search: 'https://service.feijiu.net/',
    jp_api_web_url: 'https://m.feijiu.net/'
  },
  trial: {
    api_url: 'https://apiwf.feijiu.net/',
    api_url2: 'https://feijiu-recycle.feijiu.com.cn/',
    jp_api_url: 'https://webservice.feijiu.net/',
    jp_api_url_search: 'https://service.feijiu.net/',
    jp_api_web_url: 'https://m.feijiu.net/'
  },
  release: {
    api_url: 'https://apiwf.feijiu.net/',
    api_url2: 'https://feijiu-recycle.feijiu.com.cn/',
    jp_api_url: 'https://webservice.feijiu.net/',
    jp_api_url_search: 'https://service.feijiu.net/',
    jp_api_web_url: 'https://m.feijiu.net/'
  }
}
App({
  data: {
    strRSA: 'B19pHBMJrHpIhQvrhUmeSRAipcugPyXlD8vfXoind',
    api_key: "u2fsdgvkwvjf1by07u7mtsbx0qowajpq",
    api_pass: "t18kg3atmvoqloafig7lmeyqlmpehbcf",
    aesKey: 'feijiuwangappxin',
    aesiv: '0311871066668631',
    web_url: 'https://zsbpt.zaisubao.cn/index.php/Home/Erjiu/index?url=',
    //正式地址
    api_url: baseUrls[__wxConfig.envVersion].api_url,
    api_url2: baseUrls[__wxConfig.envVersion].api_url2,
    jp_api_url: baseUrls[__wxConfig.envVersion].jp_api_url,
    jp_api_url_search: baseUrls[__wxConfig.envVersion].jp_api_url_search,
    jp_api_web_url:baseUrls[__wxConfig.envVersion].jp_api_web_url,
    jp_api_key: 'u2fsdgvkwvjf1by07u7mtsbx0qowajpq',
    jp_api_pass: 't18kg3atmvoqloafig7lmeyqlmpehbcf',
    vodurl: 'http://img5.feijiu.net',
    imgUrl: 'http://style.feijiu.net/images',

  },
 
  onShow (options) {
    // Do something when show.
    // 程序一运行的时候就是为了获取生意底部那个角标
    // if (this.checkFjLogin()) {
    //   console.log('进来允许了吗!!!')
    //   let parame = {
    //     loginuid: wx.getStorageSync('FjLoginLog').UID,
    //   }
    //   this.getDaoPostSearchNew('api/FeijiuApp/Feijiu_Get_Business_GetNum_v2024', parame, (item) => {
    //     if (item.code == 200) {
    //       let dataDic = item['data']
    //       if (dataDic.dxnum == 0 && dataDic.zcnum == 0 && dataDic.pmnum == 0) {
    //         if (typeof this.getTabBar === 'function' ) {
    //           this.getTabBar((tabBar) => {
    //             tabBar.setData({
    //               isShowIcon: false,
    //             })
    //           })
    //         }
    //       }else {
    //         console.log('有加班')
    //         setTimeout(() => {
    //           console.log('使劲地道了11', this.getTabBar)
    //           if (typeof this.getTabBar === 'function' ) {
    //             console.log('function使劲地道了')
    //             this.getTabBar((tabBar) => {
    //               console.log('ftabBar使劲地道了', tabBar)
    //               tabBar.setData({
    //                 isShowIcon: true,
    //               })
    //             })
    //           }
    //         }, 5000);
            
    //       }
    //     } 
    //     wx.hideLoading()
    //   })
    // }



  },
  //新聚拍调用
  getDaoPostJp: function (api_url, api_input, cb) {
    // wx.showLoading({
    //   title: "信息加载中"       
    // })   
    var that = this;
    api_input['platform_type'] = 4
    if (api_input != '{}') {
      api_input = JSON.stringify(api_input);
    }
    var api_target = api_url.substring(api_url.lastIndexOf('/') + 1, api_url.length);
    var arr = this.creatSecretStr(api_target, api_input);
    wx.request({
      url: this.data.jp_api_url + api_url,
      data: arr,
      method: 'POST',
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        if (res.statusCode == 200) {
          return typeof cb == "function" && cb(res.data)
        }else {
          wx.hideLoading() 
        }
      },
      fail:(err)=>{
        wx.hideLoading() 
      }
    })
  },
  //新聚拍调用搜索
  getDaoPostSearch: function (api_url, api_input, cb) {
    // wx.showLoading({
    //   title: "信息加载中"       
    // })   
    var that = this;
    api_input['platform_type'] = 4
    if (api_input != '{}') {
      api_input = JSON.stringify(api_input);
    }
    var api_target = api_url.substring(api_url.lastIndexOf('/') + 1, api_url.length);
    var arr = this.creatSecretStr(api_target, api_input);
    wx.request({
      url: this.data.jp_api_url_search + api_url,
      data: arr,
      method: 'POST',
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        if (res.statusCode == 200) {
          return typeof cb == "function" && cb(res.data)
        }
      },
      // complete:function () {
      //    wx.hideLoading()
      // }
    })
  },

  //新聚拍调用搜索
  getDaoPostSearchNew: function (api_url, api_input, cb) {
    // wx.showLoading({
    //   title: "信息加载中"       
    // })   
    var that = this;
    api_input['platform_type'] = 4
    if (api_input != '{}') {
      api_input = JSON.stringify(api_input);
    }
    var api_target = api_url.substring(api_url.lastIndexOf('/') + 1, api_url.length);
    var arr = this.creatSecretStr(api_target, api_input);
    wx.request({
      url: this.data.api_url + api_url,
      data: arr,
      method: 'POST',
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        if (res.statusCode == 200) {
          return typeof cb == "function" && cb(res.data)
        }
      },
      fail: function(err) {

      },
      complete:function (err) {
        if (err.statusCode == 500) {
          that.tishi(`服务器错误状态码${err.statusCode}`)
        }else {
          setTimeout(() => {
            wx.hideLoading()
          }, 10000);
        }
      }
    })
  },



  onLaunch: function () {
    var that = this;
    const deviceInfo = wx.getDeviceInfo()
    var FjLoginLog = wx.getStorageSync('FjLoginLog');
    var system = deviceInfo.system;
    var sbtype = 0
    if (deviceInfo.system.indexOf('iOS') == -1) {
      sbtype == 1
    } else {
      sbtype == 2
    }
    var api_input = {
      sbtype: sbtype,
      sbname: deviceInfo.model,
      sbid: '',
      uid: FjLoginLog ? FjLoginLog.UID : '',
      Ly: '1'
    }
    this.getDaoPost('api/FeijiuApp/Feijiu_AddQDLog', api_input, function (r) {

    })
    wx.getSystemInfo({
      success: e => {
        that.globalData.safeArea = e.safeArea;
        //计算得到定义的状态栏高度
        that.globalData.statusBar = e.statusBarHeight; //状态栏高度               
        let custom = wx.getMenuButtonBoundingClientRect();//菜单按钮
        that.globalData.custom = custom;
        // console.log(custom)
        that.globalData.customBar = custom.bottom + custom.top - e.statusBarHeight;
        //导航高度
        let statusBarHeight = e.statusBarHeight,
          navTop = custom.top,
          navObjWid = e.windowWidth - custom.right + custom.width, // 胶囊按钮与右侧的距离 = windowWidth - right+胶囊宽度
          navHeight = statusBarHeight + custom.height + (custom.top - statusBarHeight) * 2;
        console.log((custom.top - statusBarHeight) * 2)
        this.globalData.navHeight = navHeight; //导航栏总体高度
        this.globalData.navTop = navTop; //胶囊距离顶部距离
        this.globalData.navObj = custom.height; //胶囊高度
        this.globalData.navObjWid = navObjWid; //胶囊宽度(包括右边距离)
        // console.log(navHeight, navTop, custom.height, navObjWid)
        //吸顶容器高度
        this.globalData.windowHeight = e.windowHeight,//窗口高度
          this.globalData.windowWidth = e.windowWidth,//窗口宽度
          this.globalData.screenHeight = e.screenHeight,// 屏幕高度
          this.globalData.statusBarHeight = e.statusBarHeight,//设备状态栏高度
          // this.globalData.pixelRatio=e.pixelRatio,//设备像素比
          this.globalData.tabbarHeight = (e.screenHeight - e.windowHeight - e.statusBarHeight) * e.pixelRatio

      }
    })

    // wx.setEnableDebug({
    //   enableDebug: true
    // })
    wx.request({
      url: 'https://zsbpt.zaisubao.cn/index.php/Api/Feijiu/getIp',
      data: {},
      method: 'get',
      success: function (r) {

        wx.setStorageSync('ip', r.data.ip)
      }
    });
    wx.getSystemInfo({
      success: function (e) {
        if (e.platform == 'android') {
          wx.setStorageSync('sbtype', 1)
        } else {
          wx.setStorageSync('sbtype', 2)

        }
        wx.setStorageSync('sbname', e.brand + e.model)

      }
    })
  },
  oBase64: function (str) {
    var objBase64 = new funBase64.Base64();
    var srr = objBase64.encode(str);
    return srr
  },
  //图片分割
  phoneSplit: function (photo) {
    var photolist = [];
    if (photo.length > 10) {
      photolist = photo.split("|");
    }
    return photolist;
  },

  //视频分割
  videoSplit: function (video) {
    var videolist = [];
    if (video.length > 10) {
      videolist = video.split("|");
    }
    return videolist;
  },

  photoSplitOne: function (photo) {
    var photolist = [];
    photolist = photo.split("|");
    return photolist[0];
  },
  getJuPaiDaoPost: function (api_url, api_input, cb) {
    wx.showToast({
      title: "加载中",
      icon: "loading",
    })
    var that = this;
    api_input['platform_type'] = 4
    if (api_input != '{}') {
      api_input = JSON.stringify(api_input);
    }
    var api_target = api_url.substring(api_url.lastIndexOf('/') + 1, api_url.length);
    var arr = this.creatJupaiSecretStr(api_target, api_input);
    wx.request({
      url: this.data.api_url + api_url,
      data: arr,
      method: 'POST',
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        if (res.statusCode == 200) {
          return typeof cb == "function" && cb(res.data)
        }
        // wx.hideToast()
      }
    })
  },
  creatJupaiSecretStr: function (api_target, api_input) {
    var api_timespan = this.getCurrentDate();
    api_input['platform_type'] = 4
    var api_secret = api_target + this.data.jupai_api_key + api_input + api_timespan + this.data.jupai_api_pass;
    var arr = {
      api_key: this.data.jupai_api_key,
      api_target: api_target,
      api_input: api_input,
      api_secret: this.cMd5(api_secret),
      api_timespan: api_timespan
    }
    return arr
  },
  //生成签名字串
  creatSecretStr: function (api_target, api_input) {
    var api_timespan = this.getCurrentDate();
    var api_secret = api_target + this.data.api_key + api_input + api_timespan + this.data.api_pass;
    // console.log(api_secret)
    var arr = {
      api_key: this.data.api_key,
      api_target: api_target,
      api_input: api_input,
      api_secret: this.cMd5(api_secret),
      api_timespan: api_timespan
    }
    return arr
  },
  //获取当前日期
  getCurrentDate: function () {
    var date = new Date();
    var sign1 = "-";
    var sign2 = ":";
    var year = date.getFullYear() // 年
    var month = date.getMonth() + 1; // 月
    var day = date.getDate(); // 日
    var hour = date.getHours(); // 时
    var minutes = date.getMinutes(); // 分
    var seconds = date.getSeconds() //秒   
    if (month >= 1 && month <= 9) {
      month = "0" + month;
    }
    if (day >= 0 && day <= 9) {
      day = "0" + day;
    }
    if (hour >= 0 && hour <= 9) {
      hour = "0" + hour;
    }
    if (minutes >= 0 && minutes <= 9) {
      minutes = "0" + minutes;
    }
    if (seconds >= 0 && seconds <= 9) {
      seconds = "0" + seconds;
    }
    var currentdate = year + sign1 + month + sign1 + day + " " + hour + sign2 + minutes + sign2 + seconds;
    return currentdate;
  },
  //获取/分隔的字日期
  getCurrentDateX: function () {
    var date = new Date();
    var sign1 = "/";
    var sign2 = ":";
    var year = date.getFullYear() // 年
    var month = date.getMonth() + 1; // 月
    var day = date.getDate(); // 日
    var hour = date.getHours(); // 时
    var minutes = date.getMinutes(); // 分
    var seconds = date.getSeconds() //秒   
    if (month >= 1 && month <= 9) {
      month = "0" + month;
    }
    if (day >= 0 && day <= 9) {
      day = "0" + day;
    }
    if (hour >= 0 && hour <= 9) {
      hour = "0" + hour;
    }
    if (minutes >= 0 && minutes <= 9) {
      minutes = "0" + minutes;
    }
    if (seconds >= 0 && seconds <= 9) {
      seconds = "0" + seconds;
    }
    var currentdate = year + sign1 + month + sign1 + day + " " + hour + sign2 + minutes + sign2 + seconds;
    return currentdate;
  },

  //生成md5加密
  cMd5: function (str) {
    return zhmd5.md5(str);
  },
  //post请求
  //调用方式app.getDaoPost('api/CRM/crm_Get_GqNum7Day','{}',function (res) {});
  getDaoPost: function (api_url, api_input, cb) {
    // wx.showLoading({
    //   title: "信息加载中"       
    // })   
    var that = this;
    api_input['platform_type'] = 4
    if (api_input != '{}') {
      api_input = JSON.stringify(api_input);
    }
    var api_target = api_url.substring(api_url.lastIndexOf('/') + 1, api_url.length);
    var arr = this.creatSecretStr(api_target, api_input);
    wx.request({
      url: this.data.api_url + api_url,
      data: arr,
      method: 'POST',
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        if (res.statusCode == 200) {
          //   wx.hideLoading()
          return typeof cb == "function" && cb(res.data)
        }
      },
      fail(err) {
        that.tishi(`请求失败${err}`)
        setTimeout(() => {
          wx.hideLoading()
        }, 3000);
      }
      // complete:function () {
      //    wx.hideLoading()
      // }
    })
  },
  getDaoPostN: function (api_url, api_input, cb) {
    var that = this;
    api_input['platform_type'] = 4
    if (api_input != '{}') {
      api_input = JSON.stringify(api_input);
    }
    var api_target = api_url.substring(api_url.lastIndexOf('/') + 1, api_url.length);
    var arr = this.creatSecretStr(api_target, api_input);
    wx.request({
      url: this.data.api_url + api_url,
      data: arr,
      method: 'POST',
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        if (res.statusCode == 200) {
          return typeof cb == "function" && cb(res.data)
        }else {
          wx.hideLoading()
        }
      }
    })
  },
  trim: function (str) {
    return str.replace(/\s/g, "");
  },
  //旧的post接口调用方式
  getDaoPostOld: function (api_url, api_input, cb) {
    // wx.showToast({
    //   title: "加载中",
    //   icon: "loading",      
    // })
    var that = this;
    wx.request({
      url: this.data.api_url + api_url,
      data: api_input,
      method: 'POST',
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        wx.hideToast()
        if (res.statusCode == 200) {
          return typeof cb == "function" && cb(res.data)
        }
      }
    })
  },

  //检查是否登录
  checkFjLogin: function () {
    var FjLoginLog = wx.getStorageSync('FjLoginLog');
    if (FjLoginLog.FjToken) {
      return true
    } else {
      // wx.navigateTo({ url: '../../pages/login/index' });   
      return false
    }
  },

  //aec解密
  aesDec: function (word) {
    var key = CryptoJS.enc.Utf8.parse(this.data.aesKey);
    var iv = CryptoJS.enc.Utf8.parse(this.data.aesiv);
    var decrypt = CryptoJS.AES.decrypt(word, key, {
      iv: iv,
      mode: CryptoJS.mode.CBC
    });
    return CryptoJS.enc.Utf8.stringify(decrypt).toString();
  },
  //加密
  aesAdd: function (word, key, value) {
    var key = CryptoJS.enc.Utf8.parse(key);
    var iv = CryptoJS.enc.Utf8.parse(value);
    var srcs = CryptoJS.enc.Utf8.parse(word);
    var encrypted = CryptoJS.AES.encrypt(srcs, key, {
      iv: iv,
      mode: CryptoJS.mode.CBC
    });
    return encrypted.toString();
  },

  //GET 方式获取数据
  getDaoGet: function (str, cb) {
    // wx.showToast({
    //   title: "加载中",
    //   icon: "loading",      
    // })
    var that = this;
    wx.request({
      url: that.data.api_url + str + that.data.strRSA,
      success: function (res) {
        // wx.hideToast()   
        if (res.statusCode == 200) {
          return typeof cb == "function" && cb(res.data)
        }
      }
    })
  },
  //聚拍调用接口
  postRequest: function (api_target, api_input, token, someFunction) {
    var that = this;
    // wx.showLoading({
    //   title: '加载中',
    // })
    api_input['platform_type'] = 4
    wx.request({
      url: that.data.jp_api_url + api_target, //接口地址
      data: {
        api_key: that.data.jp_api_key,
        api_target: api_target,
        api_timespan: this.getCurrentDate(),
        api_secret: that.getApiTimespan(api_target, JSON.stringify(api_input)),
        api_input: JSON.stringify(api_input),
        // api_token: token,
      },
      method: 'POST',
      header: {
        'content-type': 'application/json', // 默认值
        'Accept-Language': 'zh-CN'
      },
      success: function (res) {
        someFunction(res.data)
        // wx.hideLoading();
      }
    })
  },
  //聚拍生成验证串
  getApiTimespan: function (api_target, apiInput) {
    var Md5String = api_target + this.data.jp_api_key + apiInput + this.getCurrentDate() + this.data.jp_api_pass;
    var apiTimeSpan = this.cMd5(Md5String);
    return apiTimeSpan;
  },

  formatTime: function (number, format) {
    var formateArr = ['Y', 'M', 'D', 'h', 'm', 's'];
    var returnArr = [];
    var date = new Date(number);
    returnArr.push(date.getFullYear());
    returnArr.push(this.formatNumber(date.getMonth() + 1));
    returnArr.push(this.formatNumber(date.getDate()));
    returnArr.push(this.formatNumber(date.getHours()));
    returnArr.push(this.formatNumber(date.getMinutes()));
    returnArr.push(this.formatNumber(date.getSeconds()));
    for (var i in returnArr) {
      format = format.replace(formateArr[i], returnArr[i]);
    }
    return format;
  },
  formatNumber: function (n) {
    n = n.toString()
    return n[1] ? n : '0' + n
  },

  tishi: function (str) {
    wx.showToast({
      title: str,
      icon: 'none',
      duration: 2000
    })
  },
  tishikuang: function (str) {
    wx.showModal({
      title: 'Feijiu网提示您',
      content: str,
      showCancel: false,
      cancelColor: '#000000',
      confirmText: '确定',
      confirmColor: '#3CC51F'
    })
  },
  /**
   *  扫码支付功能
   */
  getPayPostN: function (api_url, api_input, cb) {
    var that = this;
    if (api_input != '{}') {
      api_input = JSON.stringify(api_input);
    }
    var api_target = api_url.substring(api_url.lastIndexOf('/') + 1, api_url.length);
    var arr = this.creatSecretStr(api_target, api_input);
    wx.request({
      url: this.data.api_url + api_url,
      data: arr,
      method: 'POST',
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        if (res.statusCode == 200) {
          return typeof cb == "function" && cb(res.data)
        } else {
          wx.hideLoading({
            success: () => {
              // 展示错误信息
              wx.showToast({
                title: res.data.Message || '网络出错，请检查网络或稍后再试',
                icon: 'none'
              })
            },
          })
        }
      },
      fail: function (err) {
        wx.hideLoading({
          success: (res) => {
            // 展示错误信息
            wx.showToast({
              title: '网络出错，请检查网络或稍后再试',
              icon: 'none'
            })
          },
        })
      }
    })
  },
  GetDateStr: function (date, AddDayCount) {
    var dd = new Date(date);
    dd.setDate(dd.getDate() + AddDayCount);
    var y = dd.getFullYear();
    var m = (dd.getMonth() + 1) < 10 ? "0" + (dd.getMonth() + 1) : (dd.getMonth() + 1);
    var d = dd.getDate() < 10 ? "0" + dd.getDate() : dd.getDate();
    return y + "-" + m + "-" + d;
  },
  uploadImgStr: function () {
    var str = 'FjchuzhiUMfWDoy7mGCsJeBLPf41f6HkucQjffDC';
    var rand = Math.ceil(Math.random() * 10);
    var currdate = this.getCurrentDateX();
    var md5 = this.cMd5(rand + currdate + str);
    var imgstr = this.aesAddUpImg(currdate + '|' + rand + '|' + md5);
    return imgstr;
  },
  aesAddUpImg: function (word) {
    var key = CryptoJS.enc.Utf8.parse('feijiuwangchuzhi');
    var iv = CryptoJS.enc.Utf8.parse('6478900561064411');
    var srcs = CryptoJS.enc.Utf8.parse(word);
    var encrypted = CryptoJS.AES.encrypt(srcs, key, {
      iv: iv,
      mode: CryptoJS.mode.CBC
    });
    return encrypted.toString();
  },
  //时间去掉T取相应个数
  dateformatT: function (str, num) {
    var nuwstr = str.replace('T', " ").substring(0, num);
    return nuwstr;
  },
  // HTML 支持的其他实体
  strOtherDiscode: function (str) {
    str = str.replace(/&OElig;/g, 'Œ');
    str = str.replace(/&oelig;/g, 'œ');
    str = str.replace(/&Scaron;/g, 'Š');
    str = str.replace(/&scaron;/g, 'š');
    str = str.replace(/&Yuml;/g, 'Ÿ');
    str = str.replace(/&fnof;/g, 'ƒ');
    str = str.replace(/&circ;/g, 'ˆ');
    str = str.replace(/&tilde;/g, '˜');
    str = str.replace(/&ensp;/g, '');
    str = str.replace(/&emsp;/g, '');
    str = str.replace(/&thinsp;/g, '');
    str = str.replace(/&zwnj;/g, '');
    str = str.replace(/&zwj;/g, '');
    str = str.replace(/&lrm;/g, '');
    str = str.replace(/&quot;/g, '');
    str = str.replace(/&rlm;/g, '');
    str = str.replace(/&ndash;/g, '–');
    str = str.replace(/&mdash;/g, '—');
    str = str.replace(/&lsquo;/g, '‘');
    str = str.replace(/&rsquo;/g, '’');
    str = str.replace(/&sbquo;/g, '‚');
    str = str.replace(/&ldquo;/g, '“');
    str = str.replace(/&rdquo;/g, '”');
    str = str.replace(/&bdquo;/g, '„');
    str = str.replace(/&dagger;/g, '†');
    str = str.replace(/&Dagger;/g, '‡');
    str = str.replace(/&bull;/g, '•');
    str = str.replace(/&hellip;/g, '…');
    str = str.replace(/&permil;/g, '‰');
    str = str.replace(/&prime;/g, '′');
    str = str.replace(/&Prime;/g, '″');
    str = str.replace(/&lsaquo;/g, '‹');
    str = str.replace(/&rsaquo;/g, '›');
    str = str.replace(/&oline;/g, '‾');
    str = str.replace(/&euro;/g, '€');
    str = str.replace(/&trade;/g, '™');
    str = str.replace(/&larr;/g, '←');
    str = str.replace(/&uarr;/g, '↑');
    str = str.replace(/&rarr;/g, '→');
    str = str.replace(/&darr;/g, '↓');
    str = str.replace(/&harr;/g, '↔');
    str = str.replace(/&crarr;/g, '↵');
    str = str.replace(/&lceil;/g, '⌈');
    str = str.replace(/&rceil;/g, '⌉');
    str = str.replace(/&lfloor;/g, '⌊');
    str = str.replace(/&rfloor;/g, '⌋');
    str = str.replace(/&loz;/g, '◊');
    str = str.replace(/&spades;/g, '♠');
    str = str.replace(/&clubs;/g, '♣');
    str = str.replace(/&hearts;/g, '♥');
    str = str.replace(/&diams;/g, '♦');
    str = str.replace(/&#39;/g, '\'');
    return str;
  },
  globalData: {
    statusBarHeight: wx.getSystemInfoSync()['statusBarHeight'],
    navBarHeight: 0, // 导航栏高度
    menuRight: 0, // 胶囊距右方间距（方保持左、右间距一致）
    menuTop: 0, // 胶囊距底部间距（保持底部间距一致）
    menuHeight: 0, // 胶囊高度（自定义内容可与胶囊高度保证一致）
    navHeight: 0,
    navTop: 0,
    navObj: 0,
    navObjWid: 0,
    windowHeight: 0,//窗口高度
    screenHeight: 0,// 屏幕高度
    statusBarHeight: 0,//设备状态栏高度
    pixelRatio: 0,//设备像素比
    tabbarHeight: 0,//tabbat高度
  },
  timeConvert: function (timestamp, num) { //num:0 YYYY-MM-DD  num:1  YYYY-MM-DD hh:mm:ss // timestamp:时间戳 
    timestamp = timestamp + '';
    timestamp = timestamp.length == 10 ? timestamp * 1000 : timestamp;
    var date = new Date(timestamp);
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    m = m < 10 ? ('0' + m) : m;
    var d = date.getDate();
    d = d < 10 ? ('0' + d) : d;
    var h = date.getHours();
    h = h < 10 ? ('0' + h) : h;
    var minute = date.getMinutes();
    var second = date.getSeconds();
    minute = minute < 10 ? ('0' + minute) : minute;
    second = second < 10 ? ('0' + second) : second;
    if (num == 0) {
      return y + '-' + m + '-' + d;
    } else {
      return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second;
    }
  },


  getOpenId: function () {
    var openid = wx.getStorageSync('openid');
    var that = this;
    if (openid) {
      wx.checkSession({
        fail() {
          wx.login({
            success: (res) => {
              if (res.code) {
                var api_input = {
                  code: res.code
                }
                that.getDaoPostN('api/FeijiuApp/Feijiu_XCX_GetCode', api_input, function (r) {
                  if (r.code == 200) {
                    wx.setStorageSync('openid', JSON.parse(r.data));
                  }
                })
              }
            }
          })
        }
      })
    } else {
      wx.login({
        success: (res) => {
          if (res.code) {
            var api_input = {
              code: res.code
            }
            that.getDaoPostN('api/FeijiuApp/Feijiu_XCX_GetCode', api_input, function (r) {
              if (r.code == 200) {
                wx.setStorageSync('openid', JSON.parse(r.data));
              }
            })
          }
        }
      })
    }
  },
  /**
   * 检测当前的小程序
   * 是否是最新版本，是否需要下载、更新
   */
  checkUpdateVersion() {
    //判断微信版本是否 兼容小程序更新机制API的使用
    if (wx.canIUse('getUpdateManager')) {
      //创建 UpdateManager 实例
      const updateManager = wx.getUpdateManager();
      //检测版本更新
      if (updateManager) {
        updateManager.onCheckForUpdate(function (res) {
          // 请求完新版本信息的回调
          if (res.hasUpdate) {
            //监听小程序有版本更新事件
            updateManager.onUpdateReady(function () {
              //TODO 新的版本已经下载好，调用 applyUpdate 应用新版本并重启 （ 此处进行了自动更新操作）
              updateManager.applyUpdate();
            })
            updateManager.onUpdateFailed(function () {
              // 新版本下载失败
              wx.showModal({
                title: '已经有新版本喽~',
                content: '请您删除当前小程序，到微信 “发现-小程序” 页，重新搜索打开哦~',
              })
            })
          }
        })
      }
    } else {
      //TODO 此时微信版本太低（一般而言版本都是支持的）
      wx.showModal({
        title: '溫馨提示',
        content: '当前微信版本过低，无法使用该功能，请升级到最新微信版本后重试。'
      })
    }
  }


})